#include<vector>
#include<iostream>
using namespace std;
typedef pair<int, int> pii;
void solve()
{
    int n, m;
    cin >> n >> m;
    vector<pii> a(n + 1);
    for (int i = 1; i <= n; i++)  cin >> a[i].first >> a[i].second;
    for (int i = 1; i <= n; i++) a[i].first += a[i - 1].first, a[i].second += a[i - 1].second;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int x = a[i - 1].first + m;
        int y = a[i - 1].second + m;
        ans += 4 * m;
        if (i == 1) continue;
        if (x > a[i].first) ans -= 2 * (x - a[i].first);
        if (y > a[i].second) ans -= 2 * (y - a[i].second);
    }
    cout << ans << endl;
}
signed main()
{

    int tt = 1;
    cin >> tt;
    while (tt--)solve();
    return 0;
}